This document is aimed at evaluating the imputation procedure.


Packages used

For this document we use the following packages

library(dplyr)    # Data manipulation
library(mice)     # Data imputation
library(magrittr) # Pipes
library(purrr)    # Functional programming
library(haven)    # Import data
library(DT)       # Interactive tables

Read in the data file

We read in the workspace 3. Data imputation.Rdata from the \Workspaces\ directory in the project’s root. This workspace has been generated by the document 3. Data imputation.Rmd. The proces leading to this workspace is also documented in the file 3. Data imputation.html.

load("Workspaces/3. Data imputation.Rdata")

Algorithmic convergence

To inspect the convergence of the mice algorithm.

plot(imp)


Medians

Evaluation function

evaluate.median <- function(object, column, print = TRUE){
  observed <- object$data[, column] %>%  median(na.rm = TRUE)
  imputed <- complete(object, "all")  %>% 
    map(~ median(.[, column])) %>% 
    unlist
  if (print){
    plot(1:object$m, imputed, col = mdc(2), lwd = 4, main = column, ylab = "median", xlab = "imputation")
    abline(h =  observed, col = mdc(1), lwd = 2)
  }
  return(list(observed = observed, imputed = imputed))
}
which.loop <- names(imp$data)[11:85]
for (i in 1:length(which.loop)){
  evaluate.median(imp, which.loop[i])
}


Densities

densityplot(imp, ~ F1 + F2 + F3)

densityplot(imp, ~ F4 + F5 + F6)

densityplot(imp, ~ F7 + F8 + F9)

densityplot(imp, ~ F10 + F11 + F12)

densityplot(imp, ~ F13 + F14 + F15)

densityplot(imp, ~ F16 + F17 + F18)

densityplot(imp, ~ F19 + F20 + F21)

densityplot(imp, ~ F22 + F23 + F24)

densityplot(imp, ~ F25 + F26 + F27)

densityplot(imp, ~ F28 + F29 + F30)

densityplot(imp, ~ F31 + F32 + F33)

densityplot(imp, ~ F34 + F35 + F36)

densityplot(imp, ~ F37 + F38 + F39)

densityplot(imp, ~ F40 + F41 + F42)

densityplot(imp, ~ F43 + F44 + F45)

densityplot(imp, ~ F46 + F47 + F48)

densityplot(imp, ~ F49 + F50 + F51)

densityplot(imp, ~ F52 + F53 + F54)

densityplot(imp, ~ F55 + F56 + F57)

densityplot(imp, ~ F58 + F59 + F60)

densityplot(imp, ~ F61 + F62 + F63)

densityplot(imp, ~ F64 + F65 + F66)

densityplot(imp, ~ F67 + F68 + F69)

densityplot(imp, ~ F70 + F71 + F72)

densityplot(imp, ~ F73 + F74 + F75)


End of document


sessionInfo()
## R version 4.0.3 (2020-10-10)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Catalina 10.15.7
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] DT_0.17        haven_2.3.1    purrr_0.3.4    magrittr_2.0.1 mice_3.13.0   
## [6] dplyr_1.0.4   
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_1.0.6        knitr_1.31        hms_1.0.0         tidyselect_1.1.0 
##  [5] lattice_0.20-41   R6_2.5.0          rlang_0.4.10      highr_0.8        
##  [9] stringr_1.4.0     tools_4.0.3       grid_4.0.3        broom_0.7.4      
## [13] xfun_0.21         DBI_1.1.1         htmltools_0.5.1.1 ellipsis_0.3.1   
## [17] yaml_2.2.1        digest_0.6.27     assertthat_0.2.1  tibble_3.0.6     
## [21] lifecycle_0.2.0   crayon_1.4.1      tidyr_1.1.2       htmlwidgets_1.5.3
## [25] vctrs_0.3.6       glue_1.4.2        evaluate_0.14     rmarkdown_2.6    
## [29] stringi_1.5.3     compiler_4.0.3    pillar_1.4.7      forcats_0.5.1    
## [33] backports_1.2.1   generics_0.1.0    pkgconfig_2.0.3